#ifndef BALLFM_H
#define BALLFM_H

#include "csballfm.h"
#include "memofm.h"

typedef enum {bsItem, bsBall, bsTransBall, bsTransItem} SBallState;
typedef enum {ssBlocked, ssReady, ssDone, ssReturn} SSendState;

struct SMessage
{
//    QString name;
    QString uin;
    QString text;
    int x, y;
    int vx, vy;
    int r;
};

class SBallForm : public SCustomBallForm
{
Q_OBJECT
private:
    int lastx, lasty;
    bool FActive;

    SBallState State;
    SSendState SendState;

    SMemoForm *MemoForm;
    SBallModel *BallModel;

    QString UIN;
    QString FCaption;

//    void TransformToBall();
//    void TransformToItem();

    void sendMessage();

private slots:
    void onTimer(QObject *sender);
    void onBounce(SBounceEdges edges);

protected slots:
    void PaintBack(QImage *img);
    void onCtrlEnter();

protected:
    void wheelEvent(QWheelEvent *wheel);
    void mousePressEvent(QMouseEvent *mouse);
    void mouseReleaseEvent(QMouseEvent *mouse);
    void mouseDoubleClickEvent(QMouseEvent *mouse);
    void keyPressEvent(QKeyEvent *key);

    virtual void setFrame(QRect frame);

public:
    explicit SBallForm(QWidget* Parent, QString Uin, QString Caption="");
    ~SBallForm();

    void setTitle(QString caption);
    void setActive(bool val);
    void setAlpha(int alpha);
    void setVisible(bool visible);
    void setColor(QColor color);

    inline QString& uin() {return UIN;}

    static bool Connected;

    void TransformToBall();
    void TransformToItem();

signals:
    //void onBounce(SBallForm *sender);
    void send(SMessage *msg);
    void wantClose();

public slots:
    void receive(SMessage *msg);
    void close();
};

#endif // BALLFM_H
